home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / bsrc_250.zip / EVTPARSE.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  16KB  |  506 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                 This module was written by Bob Hartman                   */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                     BinkleyTerm Scheduler Routines                       */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. char *start_time (BINK_EVENT *, char *);
  51. char *end_time (BINK_EVENT *, char *);
  52.  
  53.  
  54. char *start_time (BINK_EVENTP e, char *p)
  55. {
  56.    int i, j, k, l, n;
  57.  
  58.    if ((n = sscanf (p, "%d:%d,%d,%d", &i, &j, &k, &l)) < 2)
  59.       {
  60.       return NULL;
  61.       }
  62.  
  63.    e->minute = i * 60 + j;
  64.    if ((e->minute < 0) || (e->minute > (24 * 60)))
  65.       {
  66.       return (NULL);
  67.       }
  68.  
  69.    if (n >= 3)
  70.       e->month = (char)k;
  71.    if (n >= 4)
  72.       e->day = (char)l;
  73.  
  74.    p = skip_to_blank (p);
  75.  
  76.    return (p);
  77. }
  78.  
  79. char *end_time (BINK_EVENTP e, char *p)
  80. {
  81.    int i, j, k;
  82.  
  83.    if (sscanf (p, "%d:%d", &i, &j) != 2)
  84.       {
  85.       return NULL;
  86.       }
  87.  
  88.    k = i * 60 + j;
  89.    if ((k > (24 * 60)) || (k < 0))
  90.       {
  91.       return (NULL);
  92.       }
  93.  
  94.    if (k < e->minute)
  95.       {
  96.       (void) printf (MSG_TXT(M_NO_END_MIDNIGHT));
  97.       return (NULL);
  98.       }
  99.  
  100.    e->length = k - e->minute;
  101.  
  102.    p = skip_to_blank (p);
  103.  
  104.    return (p);
  105. }
  106.  
  107. int parse_event (char *e_line)
  108. {
  109.    int i, j, j1, j2;
  110.    char *p, *p1, *eptr;
  111.    BINK_EVENT e;
  112.  
  113.    /* If we already have a schedule, then forget it */
  114.    if (got_sched)
  115.       return (0);
  116.  
  117.    /* Zero out the event structure */
  118.  
  119.    (void) memset ((char *)&e, 0 , sizeof (e));
  120.  
  121.    /* Skip blanks to get to the days field */
  122.    p = skip_blanks (e_line);
  123.  
  124.    /* Parse the days field */
  125.    e.days = 0;
  126.    e.wait_time = 120;
  127.    while ((*p) && (!isspace (*p)))
  128.       {
  129.       switch (toupper (*p))
  130.          {
  131.          case 'S':                              /* Sunday or Saturday */
  132.             if (!strnicmp (p, "sun", 3))
  133.                {
  134.                e.days |= DAY_SUNDAY;
  135.                }
  136.             else if (!strnicmp (p, "sat", 3))
  137.                {
  138.                e.days |= DAY_SATURDAY;
  139.                }
  140.             else /* Error condition */ 
  141.                {
  142.                goto err;
  143.                }
  144.             p += 3;
  145.             break;
  146.  
  147.          case 'M':                              /* Monday */
  148.             if (!strnicmp (p, "mon", 3))
  149.                {
  150.                e.days |= DAY_MONDAY;
  151.                }
  152.             else /* Error condition */ 
  153.                {
  154.                goto err;
  155.                }
  156.             p += 3;
  157.             break;
  158.  
  159.          case 'T':                              /* Tuesday or Thursday */
  160.             if (!strnicmp (p, "tue", 3))
  161.                {
  162.                e.days |= DAY_TUESDAY;
  163.                }
  164.             else if (!strnicmp (p, "thu", 3))
  165.                {
  166.                e.days |= DAY_THURSDAY;
  167.                }
  168.             else /* Error condition */ 
  169.                {
  170.                goto err;
  171.                }
  172.             p += 3;
  173.             break;
  174.  
  175.          case 'W':                              /* Wednesday, Week or
  176.                                                   * Weekend */
  177.             if (!strnicmp (p, "wed", 3))
  178.                {
  179.                e.days |= DAY_WEDNESDAY;
  180.                p += 3;
  181.                }
  182.             else if (!strnicmp (p, "week", 4))
  183.                {
  184.                e.days |= DAY_WEEK;
  185.                p += 4;
  186.                }
  187.             else if (!strnicmp (p, "wkend", 5))
  188.                {
  189.                e.days |= DAY_WKEND;
  190.                p += 5;
  191.                }
  192.             else /* Error condition */ 
  193.                {
  194.                goto err;
  195.                }
  196.             break;
  197.  
  198.          case 'F':                              /* Friday */
  199.             if (!strnicmp (p, "fri", 3))
  200.                {
  201.                e.days |= DAY_FRIDAY;
  202.                }
  203.             else /* Error condition */ 
  204.                {
  205.                goto err;
  206.                }
  207.             p += 3;
  208.             break;
  209.  
  210.          case 'A':                              /* All */
  211.             if (!strnicmp (p, "all", 3))
  212.                {
  213.                e.days |= (DAY_WEEK | DAY_WKEND);
  214.                }
  215.             else /* Error condition */ 
  216.                {
  217.                goto err;
  218.                }
  219.             p += 3;
  220.             break;
  221.  
  222.          default:                               /* Error condition */
  223.             goto err;
  224.          }
  225.  
  226.       if (*p == '|')
  227.          ++p;
  228.       }
  229.  
  230.    /* Did we get something valid? */
  231.    if (e.days == 0)
  232.       {
  233.       goto err;
  234.       }
  235.  
  236.    /* Skip blanks to get to the start-time field */
  237.    p = skip_blanks (p);
  238.  
  239.    /* Parse the start-time field */
  240.    if ((p = start_time (&e, p)) == NULL)
  241.       {
  242.       eptr = MSG_TXT(M_INVALID_START);
  243.       goto bad_line;
  244.       }
  245.  
  246.    /* Give